package com.ll.beautymall.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ll.beautymall.R;
import com.ll.beautymall.bean.Category;
import com.ll.beautymall.widget.CircleTransform;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/23.
 */
public class CategoryAdapter extends BaseAdapter {
    private List<Category> mData;

    @Override
    public int getCount() {
        return mData != null ? mData.size() : 0;
    }

    @Override
    public Object getItem(int i) {
        return mData != null ? mData.get(i) : null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.gv_item_category, viewGroup, false);
        ViewHolder holder = new ViewHolder(view);
        holder.tvCategoryTitle.setText(mData.get(i).getTitle());
        Picasso.with(viewGroup.getContext()).load(mData.get(i).getPic_url()).transform(new CircleTransform()).into(holder.ivCategoryCover);
        return view;
    }

    public void setData(List<Category> data) {
        this.mData = data;
        notifyDataSetChanged();
    }

    static class ViewHolder {
        @BindView(R.id.iv_category_cover)
        ImageView ivCategoryCover;
        @BindView(R.id.tv_category_title)
        TextView tvCategoryTitle;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
